package com.cn.scenario.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cn.scenario.entity.AppUser;
import com.cn.scenario.service.AppUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author Boolean
 * @Date 2022/12/22 17:13
 * @Version 1.0
 */
@RestController
@RequestMapping("/appuser")
public class AppUserController {

    @Resource
    private AppUserService appUserService;

    /**
     * 根据 id 查询详情
     *
     * @param id id
     * @return json string
     */
    @GetMapping("/{id}")
    //@RequiresPermissions("user:add")
    public String getAppUser(@PathVariable String id) {
        AppUser appuser = appUserService.getAppUserById(id);
        if (BeanUtil.isEmpty(appuser)) {
            return "暂无该人员！";
        }
        return JSONUtil.toJsonStr(appuser);
    }

    /**
     * 添加
     *
     * @param appUser 人员信息
     * @return boolean
     */
    @PostMapping("/add")
    public Boolean addAppUser(@RequestBody AppUser appUser) {
        return appUserService.addAppUser(appUser);
    }

    @DeleteMapping("/{id}")
    public Boolean delAppUser(@PathVariable String id) {
        return appUserService.removeById(id);
    }

    /**
     * @description: 修改人员信息
     * @author: 任秀兴
     * @date: 2023/1/3 10:54
     * @param: [appUser]
     * @return: java.lang.Boolean
     **/
    @PutMapping("/update")
    public Boolean updateAppUser(@RequestBody AppUser appUser) {
        return appUserService.updateAppUser(appUser);
    }
}
